
<div class="form">
	<p></p>
	<form id="ndk-health-form" method="post" action="<?php echo Yii::app()->createUrl('/soa/showGeneralledger'); ?>" target="_blank">
		<div class="row">
			<div class="col-md-4">
				<div class="widget box">
					<div class="widget-header">
						<h4><i class="icon-reorder"></i> Report General Ledger </h4>
					</div>
					<div class="widget-content">
						<div class="control-group">
						<label class="control-label">Nama Akun</label>
						<div class="controls">
<select name="cb_coa" id="cb_coa" class="select2-select-00 col-md-12 full-width-fix">
							<option></option>
							<?php 
							$sql = " 
								select case when a.code like '%00' then '<b>'||a.name||'</b>'
	else (select b.name from mst_coa b 
	where b.code = split_part(a.code, '.', 1)||'.00' )||' '||a.name 
	end as name,a.id,a.code
	from mst_coa a
	order by a.code
							";
							$cmd = Yii::app()->db->createCommand($sql);
							$data = $cmd->queryAll();
							
							foreach($data as $datas):
							?>
							<option value="<?=$datas['code'];?>"><?=$datas['name']." (".$datas['code'].")";?></option>
							<?php endforeach; ?>
						</select>
						</div>
						</div>
						<div class="control-group">
						<label class="control-label">Bulan</label>
						<div class="controls">
							<select id="bulan" name="bulan" class="form-control">
						<option value="01">Januari</option>
						<option value="02">Februari</option>
						<option value="03">Maret</option>
						<option value="04">April</option>
						<option value="05">Mei</option>
						<option value="06">Juni</option>
						<option value="07">Juli</option>
						<option value="08">Agustus</option>
						<option value="09">September</option>
						<option value="10">Oktober</option>
						<option value="11">November</option>
						<option value="12">Desember</option>
						</select>
						</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		<div class="row">
			<div class="col-md-4">
				<div class="form-actions">
					<button class="btn btn-primary btn-large" id="btn_prev" type="button">Preview</button>
					<button class="btn btn-primary btn-large" name="yt0" type="submit">Cetak</button>
				</div>
			</div>
		</div>
	</form>
</div>
<div class="form">
Rupiah
</div>
<div class="form">
<table class="table table-hover table-striped table-bordered table-highlight-head" id="tbl_gl">
	<thead>
		<tr>
			<th>Date</th>
			<th>Ref. No.</th>
			<th>Description</th>
			<!--<th>Currency</th>-->
			<th>Debet</th>
			<th>Kredit</th>
		</tr>
	</thead>
	<tbody id="isi_cicilan">
	
	</tbody>
</table>	
</div>

<!-- 
<div class="form">
Dolar ($)
</div>
<div class="form">
<table class="table table-hover table-striped table-bordered table-highlight-head" id="tbl_gl_dolar">
	<thead>
		<tr>
			<th>Date</th>
			<th>Ref. No.</th>
			<th>Description</th>
			<th>Currency</th>
			<th>Debet</th>
			<th>Kredit</th>
		</tr>
	</thead>
	<tbody id="isi_cicilan_dolar">
	
	</tbody>
	</table>
</div>
<div class="form">
Euro
</div>
<div class="form">
<table class="table table-hover table-striped table-bordered table-highlight-head" id="tbl_gl_euro">
	<thead>
		<tr>
			<th>Date</th>
			<th>Ref. No.</th>
			<th>Description</th>
			<th>Currency</th>
			<th>Debet</th>
			<th>Kredit</th>
		</tr>
	</thead>
	<tbody id="isi_cicilan_euro">
	
	</tbody>
	
	</table>
</div>
-->
<script type="text/javascript">
function formatCurrency(total) {
    var neg = false;
    if(total < 0) {
        neg = true;
        total = Math.abs(total);
    }
    return (neg ? "" : '') + parseFloat(total, 10).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,").toString();
}

$("#btn_prev").click(function(e){
	var isi_cicilan = "";
	$.ajax({
			type:"POST",
            url:"<?php echo Yii::app()->createUrl('/Soa/showGeneralledger'); ?>",
			data:{'id_coa':$("#cb_coa").val()},
			dataType:"json",
            success:function(data){
				$("#isi_cicilan").html("");
				//$("#isi_cicilan_dolar").html("");
				//$("#isi_cicilan_euro").html("");
				var total_debet_rp = parseInt(0);
				var total_kredit_rp = parseInt(0);
				
				//var total_debet_dolar = parseInt(0);
				//var total_kredit_dolar = parseInt(0);
				
				//var total_debet_euro = parseInt(0);
				//var total_kredit_euro = parseInt(0);
				for(var i=0;i<data.length;i++){
					//if(data[i].jns_mata_uang == 'Rp'){
						$("#isi_cicilan").append("<tr>" +
						"<td>"+data[i].tgl_transaksi+"</td>"+
						"<td>"+data[i].nota_note+"</td>"+
						"<td>"+data[i].keterangan+"</td>"+
						//"<td>"+data[i].jns_mata_uang+"</td>"+
						"<td align='right'>"+formatCurrency(data[i].debet)+"</td>"+
						"<td align='right'>"+formatCurrency(data[i].kredit)+"</td>"+
						"</tr>");
						total_debet_rp += Math.abs(parseInt(data[i].debet));
						total_kredit_rp += Math.abs(parseInt(data[i].kredit));
					/*}else if(data[i].jns_mata_uang == '$'){
						$("#isi_cicilan_dolar").append("<tr>" +
						"<td>"+data[i].tgl_transaksi+"</td>"+
						"<td>"+data[i].nota_note+"</td>"+
						"<td>"+data[i].keterangan+"</td>"+
						"<td>"+data[i].jns_mata_uang+"</td>"+
						"<td>"+data[i].debet+"</td>"+
						"<td>"+data[i].kredit+"</td>"+
						"</tr>");
						total_debet_dolar += parseInt(data[i].debet);
						total_kredit_dolar += parseInt(data[i].kredit);
					}else if(data[i].jns_mata_uang == 'Euro'){
						$("#isi_cicilan_euro").append("<tr>" +
						"<td>"+data[i].tgl_transaksi+"</td>"+
						"<td>"+data[i].nota_note+"</td>"+
						"<td>"+data[i].keterangan+"</td>"+
						"<td>"+data[i].jns_mata_uang+"</td>"+
						"<td>"+data[i].debet+"</td>"+
						"<td>"+data[i].kredit+"</td>"+
						"</tr>");
						total_debet_euro += parseInt(data[i].debet);
						total_kredit_euro += parseInt(data[i].kredit);
					}*/
				}
				//row total
				$("#isi_cicilan").append("<tr>" +
						"<td colspan='3' align='right'>Total</td>"+
						"<td align='right'>"+formatCurrency(total_debet_rp)+"</td>"+
						"<td align='right'>"+formatCurrency(total_kredit_rp)+"</td>"+
						"</tr>");
						
				/*$("#isi_cicilan_dolar").append("<tr>" +
						"<td colspan='4' align='right'>Total</td>"+
						"<td>"+total_debet_dolar+"</td>"+
						"<td>"+total_kredit_dolar+"</td>"+
						"</tr>");
						
				$("#isi_cicilan_euro").append("<tr>" +
						"<td colspan='4' align='right'>Total</td>"+
						"<td>"+total_debet_euro+"</td>"+
						"<td>"+total_kredit_euro+"</td>"+
						"</tr>");*/
						
				//row grand total
				var tanda = "";
				if(parseInt(total_debet_rp) < parseInt(total_kredit_rp)){
					tanda = "(-)";
				}
				$("#isi_cicilan").append("<tr>" +
						"<td colspan='3' align='right'>Grand Total</td>"+
						"<td colspan='2'>"+tanda+" "+formatCurrency((parseInt(total_debet_rp) - parseInt(total_kredit_rp)))+"</td>"+
						"</tr>");
						
				/*$("#isi_cicilan_dolar").append("<tr>" +
						"<td colspan='4' align='right'>Total</td>"+
						"<td colspan='2'>"+(parseInt(total_debet_dolar) - parseInt(total_kredit_dolar))+"</td>"+
						"</tr>");
						
				$("#isi_cicilan_euro").append("<tr>" +
						"<td colspan='4' align='right'>Total</td>"+
						"<td colspan='2'>"+(parseInt(total_debet_euro) - parseInt(total_kredit_euro))+"</td>"+
						"</tr>");*/
				
				
			}
	});
});//end click


</script>